var vmNavigation = new Vue({
    el: '#main-block',
    data: function(){
        return {
            type: 'user',
            userForm: {
                passLevel: '1',
                forbid: '',
                randCode: true,
                registerItem: [
                    {
                        name: '邮箱',
                        code: 'email',
                        show: true,
                        must: true,
                        auth: false
                    },
                    {
                        name: '手机号',
                        code: 'mobile',
                        show: true,
                        must: false,
                        auth: false
                    }
                ]
            },
            rulesUser: {
                passLevel: [{ required: true, message: '请选择密码复杂度', trigger: 'blur' }]
            }
        };
    },
    methods: {
        /**
         * 切换模板.
         */
        handleClick: function() {
            this.loadData();
        },
        /**
         * 加载数据.
         */
        loadData: function() {
            switch (this.type) {
                case 'user':
                default:
                    this.loadDataUser();
                    break;
            }
        },
        /**
         * 加载用户注册项数据.
         */
        loadDataUser: function() {
            var self = this;
            var request = {};

            var fn="operationSetUserGet";
            var service = Commonjs.jsonToString(request);
            var params = Commonjs.getParams(fn, service);
            Commonjs.ajaxSilence(weburl, params, true, function (response) {
                var data = response.data;
                if (data.passLevel) {
                    self.userForm = $.extend(self.userForm, data);
                }
            }, function () {
                self.$message.error("获取用户注册选项配置错误");
            });
        },
        /**
         * 保存用户修改.
         */
        saveUser: function () {
            var self = this;
            var request = {user: self.userForm};

            var fn="operationSetUserSave";
            var service = Commonjs.jsonToString(request);
            var params = Commonjs.getParams(fn, service);
            Commonjs.ajaxSilence(weburl, params, true, function (response) {
                self.$message.success("保存用户注册选项成功")
            }, function () {
                self.$message.error("保存 用户注册选项配置错误");
            });
        }
    },
    mounted:function () {
        this.loadData();
    }
});
